package com.ysd.lis.service.impl;

import cn.hutool.core.date.DateUtil;
import com.ysd.common.Result;
import com.ysd.lis.entity.WkContentViewTime;
import com.ysd.lis.mapper.WkContentViewTimeMapper;
import com.ysd.lis.service.WkContentViewTimeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 培训知识预览时间统计 服务实现类
 * </p>
 *
 * @author LiuQi
 * @since 2024-03-28
 */
@Service
public class WkContentViewTimeServiceImpl extends ServiceImpl<WkContentViewTimeMapper, WkContentViewTime> implements WkContentViewTimeService {

    @Autowired
    WkContentViewTimeMapper wkContentViewTimeMapper;

    @Override
    public Result addContentViewTime(WkContentViewTime wkContentViewTime) {
        long duration = DateUtil.betweenMs(wkContentViewTime.getStartTime(), wkContentViewTime.getEndTime());
        wkContentViewTime.setDuration(duration);
        boolean save = this.save(wkContentViewTime);
        if (save) {
            return Result.succ(1, "保存成功！", save);
        } else {
            return Result.fail("保存失败");
        }
    }

}
